Skip to main content

Crate markdown

Crate markdown 

Source
Expand description

A Notion-style block document model, with markdown as the wire form.

let doc = markdown::parse("# Title\n\n- a\n- b");
assert_eq!(doc.blocks.len(), 3);
assert_eq!(markdown::serialize(&doc), "# Title\n\n- a\n- b");

The model is a flat list of blocks with an indent level (Doc), not a nested tree — Notion’s shape rather than CommonMark’s, chosen because editing a flat list is list operations while editing a tree is restructuring. [parse] and [serialize] are inverses up to a fixed point: parsing, serializing and parsing again always lands on the same document, so an edit/save cycle cannot drift.

doc, [parse], [serialize], select and edit are pure — no gpui, no painting — and [render] is the gpui layer over them, caret and selection included for a caller that owns them. The editing surface is the editor crate.

Everything that paints is behind the gpui feature, on by default. Without it the crate is the document model alone and builds for wasm32-unknown-unknown.

An image at an http URL — a picture, a favicon, a bookmark’s cover — needs an http client on the app, which gpui_platform::application installs and a hand-built gpui::Application does not. gpui’s own default is a NullHttpClient, and the failure is silent: the element paints the same fallback it would show while a fetch was still in flight.

Re-exports§

pub use app::AppExt;
pub use app::layout::Layout;
pub use app::picture::PictureMenu;
pub use app::preview::Preview;
pub use app::typography::Typography;
pub use doc::Align;
pub use doc::Block;
pub use doc::BlockKind;
pub use doc::Doc;
pub use doc::Form;
pub use doc::Mark;
pub use doc::MarkSpan;
pub use doc::Part;
pub use doc::QuoteKind;
pub use doc::Quoted;
pub use doc::Text;
pub use edit::Shortcut;
pub use edit::Splice;
pub use edit::shortcut;
pub use fence::BlockRenderer;
pub use fence::Fence;
pub use fence::Rewrite;
pub use fence::highlight::Highlighter;
pub use marks::Marks;
pub use paint::comment::CommentPaint;
pub use paint::comment::CommentWashes;
pub use paint::comment::default_comment;
pub use paint::find::FindPaint;
pub use paint::find::default_find;
pub use paint::find::find_washes;
pub use paint::marks::HighlightColor;
pub use paint::marks::HighlightPaint;
pub use paint::marks::MarkPaint;
pub use paint::marks::default_highlight;
pub use paint::marks::highlight_solid;
pub use paint::marks::highlight_wash;
pub use parse::ParsedDoc;
pub use parse::is_image;
pub use parse::is_url;
pub use parse::parse;
pub use parse::parse_at;
pub use parse::parse_at_many;
pub use parse::parse_ranges;
pub use parse::parse_ranges_with;
pub use parse::parse_with;
pub use quote::Quote;
pub use render::Annotation;
pub use render::BlockLayouts;
pub use render::Caption;
pub use render::CopyButton;
pub use render::Editing;
pub use render::FenceHost;
pub use render::ImageOverlay;
pub use render::ImageOverlayCorner;
pub use render::LeaveBlock;
pub use render::OnImage;
pub use render::OnImageMenu;
pub use render::OnJump;
pub use render::OnLeave;
pub use render::OnResize;
pub use render::OnRewrite;
pub use render::OnToggle;
pub use render::PAINTED_CONTEXT;
pub use render::RevealMode;
pub use render::SourceText;
pub use render::SpanJob;
pub use render::Spans;
pub use render::Toggle;
pub use render::image_source;
pub use render::markdown;
pub use render::render;
pub use render::render_source;
pub use render::render_with;
pub use select::Affinity;
pub use select::Cursor;
pub use select::Selection;
pub use serialize::serialize;
pub use serialize::serialize_at;
pub use serialize::serialize_at_many;
pub use serialize::serialize_with;
pub use source::spans as source_spans;
pub use source::style::SourceStyle;
pub use synced::Synced;

Modules§

app
App-owned configuration.
doc
The document model.
edit
Editing a Doc.
fence
Who paints a fenced block.
marks
The inline marks an app spells itself.
paint
Paint laid over a document’s text: registered marks, highlights, comment ranges and find matches.
parse
Markdown → Doc.
quote
Finding a range again in a document edited somewhere this crate never saw.
render
Doc → gpui elements.
select
Positions and ranges in a Doc.
serialize
Doc → markdown.
source
Colouring markdown source.
synced
A document held as markdown and as blocks at once.